
<include file="mobile/Public/header" />

<link rel="stylesheet" href="__CSS__/good.css">
<style>
	.star-section{padding: 1.5rem}
	.star-section img{ padding: 0.3rem;width: 1.6667rem}
	.comment-section{padding:0 0.834rem}
	.comment-section textarea{width: 100%;border-radius: 3px;height: 7rem;resize: none;border: thin solid #dadada;padding: 0.7rem}
	.pic-content{padding:0.834rem}
	.pic-content section{ height: 0;width: 22%;position: relative;padding:0 0 22%;float: left;margin-right: 4%;margin-bottom: 1rem;background: white}
	.pic-content section:nth-child(4n){margin-right: 0}
	.pic-content section>.square-div{ position: absolute;height: 100%;width: 100%}
	.square-div>img{width: 100%;height: 100%;border: thin solid #dadada}
	.icon-img{padding:1.5rem}
</style>
<header class="color-main vertical-box">
	<span class="header-title">发表评论</span>
	<div class="header-left vertical-box">
		<img class="img-btn" src="__IMG__/back.png" onclick="history.back()">
	</div>
	<div class="header-right vertical-box">
		<img class="img-btn" src="__IMG__/home.png" onclick="window.location.href='{:U('shop/index/index')}'">
	</div>
</header>
<article class="">
	<?php
		foreach($order['products'] as $product)
		{
	?>
	<article class="order_products">
		<section class="good-section linear-section margin-top">
			<div class="good-section-left">
				<img class="good-section-img" src="<?php if($product['main_img']) echo pic($product['main_img']) ?>">
			</div>
			<div class="good-section-right border-box">
				<p class="good-section-title"><?php if($product['title']) echo $product['title'] ?></p>
				<?php
				$sku_index =strpos($product['sku_id'],';');
				if(!empty($sku_index)){
					?>
					<p class="good-section-option small-text tips-font">
						<?php echo substr($product['sku_id'],strpos($product['sku_id'],';')+1);?>
					</p>
					<?php
				}
				?>
				<p class="good-section-option small-text tips-font clearfix">
					￥<?php if($product['paid_price']) echo sprintf("%.2f", $product['paid_price']/100) ?> x <?php if($product['quantity']) echo $product['quantity'] ?>
					<span class="big-text good-section-price secondary-font">
                    ￥<?php if($product['paid_price']) echo sprintf("%.2f", $product['paid_price']*$product['quantity']/100) ?>
                </span>
				</p>
			</div>
		</section>
		<section class="star-section">
			<img class="active-star" src="__IMG__/star1.png">
			<img class="active-star" src="__IMG__/star1.png">
			<img class="active-star" src="__IMG__/star1.png">
			<img class="active-star" src="__IMG__/star1.png">
			<img class="active-star" src="__IMG__/star1.png">
		</section>
		<section class="comment-section">
			<textarea class="brief-textarea border-box" placeholder="亲，您的评价对其他买家有很大帮助"></textarea>
		</section>
<!--		<section class="pic-content clearfix">-->
<!--			<section id="uploadBtn" class="upload-btn icon-section">-->
<!--				<div class="square-div">-->
<!--					<img class="icon-img border-box" src="__IMG__/add.png">-->
<!--				</div></section>-->
<!--			<script id="pic-tpl" type="text/x-dot-template">-->
<!--				<section class="pic-section"><div class="square-div">-->
<!--						<img class="good-img" src="{{=it}}">-->
<!--					</div></section>-->
<!--			</script>-->
<!--		</section>-->
	</article>
	<?php  }?>
	<footer class="btn-footer footer-one-btn margin-bottom">
		<button class="saveComment color-primary">提交评论</button>
	</footer>
</article>

<include file="mobile/Public/footer" />

<script>
	var order_data = <?php echo(!empty($order)? json_encode($order):"null")?>;//useful
	//'jquery' or 'zepto' 脚本入口,按情况选择加载
	seajs.use(['jquery','doT'], function () {
		$(document).ready(function () {

//			seajs.use('plupload',function ()
//			{
//				var uploader_img = new plupload.Uploader({
//					browse_button: 'uploadBtn',
//					url:  "{:U('Core/File/uploadPicture',array('session_id'=>session_id()))}",
//					filters: {
//						max_file_size: '20mb',
//						mime_types: [
//							{title: "Image files", extensions: "jpg,gif,png,bmp"}
//						]
//					},
//					init: {
//						FilesAdded: function (up, files) {
//							uploader_img.start();
//						},
//						FileUploaded: function (up, files, res) {
//							res = JSON.parse(res.response); //PHP上传成功后返回的参数
//							console.log(res,res.data.file.path);
//							if(res.status){
//								var picTpl = doT.template($('#pic-tpl').text());
//								$('#uploadBtn').after(picTpl(res.data.file.path))
//							}
//							else
//							{
//								alert(res.info)
//							}
//						},
//						Error: function (upload,error) {
//							alert('上传失败，未知错误:'+error.code)
//							if(error.code==(-600)){
//								alert('图片大小为0-1mb范围内')
//							}
//							else{
//								alert('上传失败，未知错误:'+error.code)
//							}
//						}
//					}
//				});
//				uploader_img.init();
//			});
			
			$('.star-section img').click(function () {
				$(this)
					.attr('src','__IMG__/star1.png').addClass('active-star')
					.prevAll().attr('src','__IMG__/star1.png').addClass('active-star');
				$(this).nextAll().attr('src','__IMG__/star1_.png').removeClass('active-star');
			});
			$('.pic-content').on('click','.pic-section', function () {
				if(confirm('您想取消此图片吗？')){
					$(this).remove()
				}
			});
			$('.saveComment').click(function () {
				var error = 0;
				var product_comment = {};
				$('.order_products').each(function (index) {
					var brief = $(this).find('.brief-textarea').val().trim();
					console.log(brief);
					if(brief==''){
						alert('评价不能为空');
						error = 1;
						return
					}
					var images = [];
					$(this).find('.pic-section').each(function () {
						var src = $(this).find('.good-img').attr('src');
						images.push(src)
					});
					images = images.join(';');
					product_comment[index] = {
						product_id:order_data.products[index].sku_id,
						sku_id:order_data.products[index].sku_id,
						score:$(this).find('.active-star').length,
						brief:brief,
						images:images,
						order_id:order_data.id
					}
				});
				if(error) return;
				var data = {
					product_comment:product_comment
				};
				$.post('{:U('shop/index/comment')}',data, function (ret) {
//					ret = JSON.parse(ret);
					if(ret.status==1){
						alert('评论成功');
						history.back()
					}
					else{
						alert('评论失败，'+ret.info);
//						history.back()
					}

				})
			})
		})
	});
</script>
</body>
</html>